package com.example.second_home_work

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.*
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val linearLayout = findViewById<LinearLayout>(R.id.linearLayout)
        val addTextViewButton = findViewById<Button>(R.id.addTextViewButton)
        val languageSpinner = findViewById<Spinner>(R.id.languageSpinner)
        val submitButton = findViewById<Button>(R.id.submitButton)
        val resultTextView = findViewById<TextView>(R.id.resultTextView)

        var textViewCount = 0
        addTextViewButton.setOnClickListener {
            val newTextView = TextView(this)
            textViewCount++
            newTextView.text = "This is a new textView: $textViewCount"
            newTextView.textSize = 18f
            linearLayout.addView(newTextView)
        }
        val languages = arrayOf("Java", "Kotlin", "Python")
        val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, languages)
        languageSpinner.adapter = adapter
        val adviser = ProgramAdviser()

        submitButton.setOnClickListener {
            val selectedLanguage = languageSpinner.selectedItem.toString()
            val advice = adviser.getAdvice(selectedLanguage)
            resultTextView.text = advice
        }
    }
}
class ProgramAdviser {
    fun getAdvice(language: String): String {
        return when (language) {
            "Java" -> "You chose Java. Keep going!"
            "Kotlin" -> "Kotlin is the future of Android development!"
            "Python" -> "Python is great for data science."
            else -> "Choose a programming language to get advice."
        }
    }
}
